package com.dtborad.myblog.controller;

import com.dtborad.myblog.common.AIChatUtil;
import com.dtborad.myblog.common.Result;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@Slf4j
@RequestMapping("/v1")
@Api(tags = "AI模块")
@CrossOrigin(origins = "*")
public class AIChatController {
    @Autowired
    private AIChatUtil aiChatUtil;

    @PostMapping("/chat")
    public Result<String> chat(@RequestBody Map<String, String> requestBody) {
        String content = requestBody.get("content");
        //System.out.println("content---" + content);
        String response = "";
        try {
            response = aiChatUtil.getAIResponse(content);
        }catch (Exception e){
            return Result.ofFail("500", e.getMessage());
        }
        return Result.ofSuccess(response);
    }
}
